﻿// MIT License
// 开源地址：https://gitee.com/co1024/AbcMvc
// Copyright (c) 2021-2023 1024
// Abc.Mvc=Furion+EF+SqlSugar+Pear layui admin.

namespace Abc.Utils;

/// <summary>
///     ElasticSearhch 配置选项
/// </summary>
public class EsLoggingConfigOptions : IConfigurableOptionsListener<EsLoggingConfigOptions>
{
    /// <summary>
    ///     服务器地址
    /// </summary>
    public List<string> Urls { get; set; }

    /// <summary>
    ///     默认索引
    /// </summary>
    public string DefaultIndex { get; set; } = "AbcLogs";

    /// <summary>
    ///     账号
    /// </summary>
    public string AuthUserName { get; set; }

    /// <summary>
    ///     密码
    /// </summary>
    public string AuthPassword { get; set; }

    public void OnListener(EsLoggingConfigOptions options, IConfiguration configuration)
    {
        var entityType = GetType(); //获得该类的Type

        var dics = options.GetDictionary();
        foreach (var item in dics)
        {
            var propertyInfo = entityType.GetProperty(item.Key);
            propertyInfo?.FieldSetValue(item.Key, item.Value);
        }
    }

    public void PostConfigure(EsLoggingConfigOptions options, IConfiguration configuration)
    {
    }
}